package leetcode_core.leetcode_1;

import org.junit.Test;

public class LongestCommonSubsequence {
    public int longestCommonSubsequence(String text1,String text2){
        if(text1.length() == 0 || text2.length() == 0){
            return 0;
        }
        //1.定义dp数组,定义为dp[i][j]:text1的第i个字符与text2的第j个字符所形成的最长串长度
        int[][] dp = new int[text1.length()+5][text2.length()+5];
        //2.对base-case进行初始化
        for(int i = 0;i<=text1.length();i++){
            dp[i][0]= 0;
        }
        for(int j = 0;j<=text2.length();j++){
            dp[0][j] = 0;
        }
        for(int i = 1;i<=text1.length();i++){
            for(int j = 1;j<= text2.length();j++){
                if(text1.charAt(i-1) == text2.charAt(j-1)){
                    dp[i][j] = dp[i-1][j-1]+1;
                }else{

                }
            }
        }
        return dp[text1.length()][text2.length()];
    }
    @Test
    void test(){
        System.out.println(longestCommonSubsequence("",""));
    }
}
